package cn.kawa;

import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
// 标识当前是一个Eureka客户端，开启Eureka客户端功能，只要导入了Eureka依赖不加此注解默认也开启客户端功能
@EnableEurekaClient
//启用熔断器
@EnableCircuitBreaker
public class OrderServerApp {

    public static void main(String[] args) {
        SpringApplication.run(OrderServerApp.class, args);
    }

    @Bean // 让当前返回的对象成为一个bean对象
    @LoadBalanced//让当前的RestTemplate（OrderServer）有负载均衡（分发）能力

    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    //负载均衡的随机算法
    @Bean
    public RandomRule randomRule(){
        return new RandomRule();
    }


}